View Javadoc

1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: AbstractHTTPConnectorCfg.java,v 1.5 2005/12/01 13:53:23 tanderson Exp $
44   */
45  package org.exolab.jms.server.net;
46  
47  import org.exolab.jms.config.ConfigHelper;
48  import org.exolab.jms.config.Configuration;
49  import org.exolab.jms.config.HttpConfigurationType;
50  import org.exolab.jms.config.ServerConfiguration;
51  import org.exolab.jms.config.types.SchemeType;
52  import org.exolab.jms.net.socket.SocketRequestInfo;
53  import org.exolab.jms.net.uri.URI;
54  import org.exolab.jms.net.util.Properties;
55  import org.exolab.jms.net.connector.ResourceException;
56  
57  
58  /***
59   * Configuration for the HTTP/HTTPS connectors.
60   *
61   * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
62   * @version $Revision: 1.5 $ $Date: 2005/12/01 13:53:23 $
63   */
64  abstract class AbstractHTTPConnectorCfg extends AbstractConnectorCfg {
65  
66      /***
67       * The HTTP/HTTPS configuration.
68       */
69      private HttpConfigurationType _config;
70  
71  
72      /***
73       * Construct a new <code>AbstractHTTPConnectorCfg</code>.
74       *
75       * @param scheme     the connector scheme
76       * @param config     the configuration to use
77       * @param httpConfig the HTTP configuration
78       */
79      public AbstractHTTPConnectorCfg(SchemeType scheme, Configuration config,
80                                      HttpConfigurationType httpConfig) {
81          super(scheme, config);
82          if (httpConfig == null) {
83              throw new IllegalArgumentException("Argument 'httpConfig' is null");
84          }
85          _config = httpConfig;
86      }
87  
88      /***
89       * Returns the URI used to establsh connections to remote services.
90       *
91       * @return the URI used to establish connections to remote services
92       */
93      public String getConnectURI() {
94          return ConfigHelper.getServerURL(getScheme(), getConfiguration());
95      }
96  
97      /***
98       * Returns the URI that services are exported on.
99       *
100      * @return the URI for exporting services
101      */
102     public String getExportURI() {
103         return getExportURI(_config.getPort());
104     }
105 
106     /***
107      * Returns the URI that JNDI service is exported on.
108      *
109      * @return the JNDI service URI
110      */
111     public String getJNDIExportURI() {
112         String uri;
113         if (_config.getJndiPort() != 0) {
114             uri = getExportURI(_config.getJndiPort());
115         } else {
116             uri = getExportURI();
117         }
118         return uri;
119     }
120 
121     /***
122      * Returns the URI the administration service is exported on.
123      *
124      * @return the administration service URI
125      */
126     public String getAdminExportURI() {
127         String uri;
128         if (_config.getAdminPort() != 0) {
129             uri = getExportURI(_config.getAdminPort());
130         } else {
131             uri = getExportURI();
132         }
133         return uri;
134     }
135 
136     /***
137      * Populates the supplied properties with connection accept properties.
138      *
139      * @param properties the properties to populate
140      */
141     protected void populateAcceptProperties(Properties properties) {
142         URI uri = getURI(getExportURI());
143         try {
144             SocketRequestInfo info = new SocketRequestInfo(uri);
145             info.setBindAll(_config.getBindAll());
146             info.export(properties);
147         } catch (ResourceException exception) {
148             // should never happen.
149             throw new IllegalStateException(exception.getMessage());
150         }
151     }
152 
153     /***
154      * Generates an export URI for a particular port.
155      *
156      * @param port the port
157      * @return an export URI
158      */
159     private String getExportURI(int port) {
160         SchemeType scheme = getScheme();
161         String acceptScheme = scheme.toString() + "-server";
162         ServerConfiguration server
163                 = getConfiguration().getServerConfiguration();
164         return getURI(acceptScheme, server.getHost(), port).toString();
165     }
166 
167 }